// JavaScript Document
(function($) {
  if ($.AMUI && $.AMUI.validator) {
    // 增加单个正则
    $.AMUI.validator.patterns.mobile = /^13[0-9]{1}[0-9]{8}$|15[0-9]{1}[0-9]{8}$|18[0-9]{1}[0-9]{8}$|189[0-9]{8}$/;
  }
})(window.jQuery);

$(function() {
  $('#doc-vld-msg').validator({
    onValid: function(validity) {
      $(validity.field).closest('.am-form-group').find('.am-alert').hide();
    },

    onInValid: function(validity) {
      var $field = $(validity.field);
      var $group = $field.closest('.am-form-group');
      var $alert = $group.find('.am-alert');
      // 使用自定义的提示信息 或 插件内置的提示信息
      var msg = $field.data('validationMessage') || this.getValidationMessage(validity);

      if (!$alert.length) {
        $alert = $('<div class="am-alert am-alert-danger"></div>').hide().
          appendTo($group);
      }

      $alert.html(msg).show();
    }
  });
});

function checkMobile(v){
    if(v==""){
        return false;
    }else{
        var pattern = /^13[0-9]{1}[0-9]{8}$|15[0-9]{1}[0-9]{8}$|18[0-9]{1}[0-9]{8}$|189[0-9]{8}$/;
        flag = pattern.test(v);
        if(!flag){
            return false;
        }else{
            return true;
            }
    }
}

function checkPassword(v){
    if(v==''){
        return false;
    }else{
        var pattern = /^[A-Za-z0-9_@.-]{6,15}$/;;
        flag = pattern.test(v);
        if(!flag){
            return false;
        }else{
            return true;
            }
    }
}

function GoYzm() {
    var txtMobile = $("#username");
    var aMobile = document.getElementById("aMobile");

    if (txtMobile.val() == "") {
		alert("请输入手机号码");
        return false;
    }else{
		if(!checkMobile(txtMobile.val())){
			alert("手机号码格式不正确");
        	return false;
		}
	}

    var btnYzm = document.getElementById("btnYzm");
    if (btnYzm != undefined) {
        btnYzm.disabled = true;
    }
	
	time(btnYzm);

    $.get("index.php?g=Wap&m=Register&a=getcode&mobile="+txtMobile.val()+"&temp="+new Date().getTime(),function(response){
		if (response!='0') {
			alert("短信激活码发送失败");
		}
	})
}


var wait = 60;
function time(o) {
    if (wait == 0) {
        o.removeAttribute("disabled");
        o.value = "免费获取短信激活码";
        wait = 60;

        var btnYzm = document.getElementById("btnYzm");
        if (btnYzm != undefined) {
            btnYzm.disabled = false;
        }
    } else {
        o.setAttribute("disabled", true);
        o.value = "(" + wait + "秒后)重新获取短信";
        wait--;
        setTimeout(function () {
            time(o)
        },
            1000)
    }
}